<template>
    <div>
        <base-list ref="ship" :condition="condition" :datas.sync="ship" :pageSearch="pageSearch">
            <el-form :inline="true" :model="condition" class="search-form" slot="search" label-width="80px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="船舶代码">
                            <auto-search-ship @selectCode="v=>condition['search_EQ_shipCode']=v"></auto-search-ship>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="船舶名称">
                            <el-input v-model="condition['search_LIKE_shipCName']" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="船舶类型">
                            <!--<auto-search-dic @select="v=>condition['search_EQ_shipType']=v"-->
                                             <!--code="SHIP_TYPE"></auto-search-dic>-->
                            <el-select v-model="condition['search_EQ_shipType']" placeholder="请选择" clearable>
                                <el-option v-for="[key, val] in _dictShipType" :key="key" :label="val" :value="key">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="船公司">
                            <auto-search-custom @selectName="v=>condition['search_LIKE_shipOwnerName']=v" :isShipCompany="true"></auto-search-custom>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="船代">
                            <auto-search-custom @selectName="v=>condition['search_LIKE_shipAgentName']=v" :isShipAgent="true"></auto-search-custom>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-button type="primary" icon="el-icon-search" @click="loadData" class="ml-80">查 询</el-button>
                        <el-button formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)">新增
                        </el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-table slot="list" :data="ship" border stripe max-height="500">
                <el-table-column prop="shipCode" label="船舶代码"  min-width="110"></el-table-column>
                <el-table-column prop="shipCName" label="船舶名称" show-overflow-tooltip  min-width="110"></el-table-column>
                <el-table-column prop="shipEName" label="英文名称"  min-width="110"></el-table-column>
                <el-table-column prop="shipType" label="船舶类型"  min-width="110">
                    <template slot-scope="scope">
                        {{ scope.row.shipType | _filterShipType }}
                    </template>
                </el-table-column>
                <el-table-column prop="shipOwnerName" label="船公司" show-overflow-tooltip  min-width="200"></el-table-column>
                <el-table-column prop="shipAgentName" label="船代"  min-width="120"></el-table-column>
                <el-table-column prop="closetNumber" label="关薄号"  min-width="120"></el-table-column>
                <el-table-column prop="maxBay" label="最大贝数"  min-width="120"></el-table-column>
                <el-table-column prop="maxRow" label="最大排数"  min-width="120"></el-table-column>
                <el-table-column prop="maxTier" label="最大层高"  min-width="120"></el-table-column>
                <el-table-column prop="ediCode" label="海关EDI代码"  min-width="130"></el-table-column>
                <el-table-column prop="createBy" label="创建人"  min-width="120"></el-table-column>
                <el-table-column prop="createDateTime" label="创建时间"  min-width="160"></el-table-column>
                <el-table-column fixed="right" align="center" label="操作"  width="140">
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="handleDialogFormOpen(true,scope.row)">编辑</el-button>
                        <el-button type="text" class="danger" size="small" @click="handleRemove(scope.row.shipCode)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </base-list>
        <ship-form ref="shipForm" @load="loadData"></ship-form>
    </div>
</template>

<script>
    import { getShipList,deleteShip } from "@/api/port/port";
    import autoSearchDic from '@/components/autocomplete/autoSearchDic'
    import autoSearchCustom from '@/components/autocomplete/autoSearchCustom'
    import autoSearchShip from '@/components/autocomplete/autoSearchShip'
    import shipForm from './shipForm'

    export default {
        name: "船舶资料",
        components: { shipForm,autoSearchDic,autoSearchCustom,autoSearchShip },
        data() {
            return {
                condition: {},                      // 查询条件
                ship: [],                      // table数组
                pageSearch: getShipList,          // 分页查询api接口
            }
        },
        mounted() {
            this.loadData()
        },
        methods: {
            loadData() {
                this.$refs.ship.loadData()
            },
            handleDialogFormOpen(bool,item) {
                if (bool) {
                    const form=JSON.parse(JSON.stringify(item))
                    this.$refs.shipForm.form = form
                    this.$refs.shipForm.id = form.shipCode
                    this.$refs.shipForm.isEdit = true
                    this.$refs.shipForm.dialogForm = true
                } else {
                    this.$refs.shipForm.dialogForm = true
                }
            },
            handleRemove(id){
                this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteShip(id).then(res=>{
                        this.$message({ message: '删除成功!', type: 'success' })
                        this.loadData()
                    })
                })
            }
        },
    }
</script>

<style scoped>

</style>
